<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Market View/Edit</title>
<LINK REL="stylesheet" HREF="CSS/Main.css" TYPE="text/css">
<script type="text/javascript" src="Javascript/Market.js"></script>
<LINK REL="stylesheet" HREF="CSS/Button.css" TYPE="text/css">
</head>
<body>

       <div id="top">
             <h1>Master Data Management</h1>
             <br>
             <a id="log" href="logout">Logout</a><br>
    		<%@ include file="redirection.jsp" %>
             <div id="menu">
			      <ul>
			        <li>
			        	<form action = "logout" method="post">
							<a><input type="submit" name="Logout" value="Logout"></a>
						</form>
					</li>
			      </ul>
		    </div>
       	</div>

       <h2>Market View/Edit</h2>
       
       <div id="left" >
             <div class="box">
             
                           <%
                         	  if(request.getAttribute("fromsearch")!=null)
                  			 		request.setAttribute("fromsearch", "true");
                                 String[] mark = (String[]) request.getAttribute("market");
                          		 String[] mid = (String[]) request.getAttribute("mid");
                                 if (mark == null) {
                           %>
                           <form name='header' action='MarketEdit' method="get">
                           		<input type="hidden" name="marketid" value="<%=(String)request.getAttribute("marketid")%>">
                                 <input type="hidden" name="fromsearch" value="<%=(String)request.getAttribute("fromsearch")%>">
                                 <script type="text/javascript">
                                        document.forms['header'].submit();
                                 </script>
                           </form>
                           <%
                                 }
                           %>
                    
                           <form action="MarketEdit" method="get">
                                 <table ><tr><td>
                                 				<%String preselected =(String) request.getAttribute("preselected"); %>
                                               <select name="selected">
                                                     <%if(mark!=null){
                                                            for(int i = 0; i<mark.length;i++){%>
                                                                   
                                                          <%   if((mid[i]).equals(preselected)){%>
												<option value="<%=mid[i]%>" selected><%=mark[i]%></option>
											<%}
											else{%>
												<option value="<%=mid[i]%>"><%=mark[i]%></option>
											<%}}}%>
                                               </select> 
                                        </td>
                                 </tr></table>
                                  <input type="submit" class="button" name="show" value="Show Details">
                           </form>

             </div>
             <div class="visbox">
             <table>
                    <tr>
					<td>	
                           <form action="Search.jsp">
                                 <input type="submit" class="button" name="Back" value="Back to Search">
                           </form></td>
              <tr>
       
                   			<%if(session.getAttribute("role").equals("admin")){%>
                   			<td><form action="ControlPanel.jsp">
				<input type="submit" class="button" name="Back" value="Back to Control Panel">
			</form></td>
				<tr><td><form action="Home.jsp">
					<input type="submit" class="button"name="Home" value="Home">
				</form></td></tr>		
			<%}else{%>
			<td><form action="ControlPanelUser.jsp">
				<input type="submit" class="button" name="Back" value="Back to Control Panel">
			</form></td>
			<tr><td>	<form action="HomeUser.jsp">
					<input type="submit" class="button"name="Home" value="Home">
				</form></td>	</tr>
			<% }%>	
         
              </tr>
                    </tr>
             </table>
             </div>
       </div>
       <div id="right">
       	<form action="MarketEdit" method="post" onsubmit="return v()">
                    <%     String[] details = (String[]) request.getAttribute("marketdetails");
                    		
                           if (details != null) {  %>
                           <table border="1">
                           <tr>
                                 <th>Market Name</th>
                                 <th>Location</th>
                                 <th>Commodity Type</th>
                                 <th>Currency</th>
                                 <th>Start Date</th>
                                 <th>End Date</th>
                                 <th>Flag</th>
                           </tr>
                           <tr>
                           			
                           		<td><input type="hidden" name="marketid" value="<%=details[4]%>">
                           		<input type="text" id="marketname" name="MarketName" value="<%=details[0]%>"></td>
                           		<td>
	                           		<select name="selected1">
										<%String[] loc = (String[]) request.getAttribute("Location");
										if(loc!=null){
											for(String s:loc){
												if(s.equals(details[1])){%>
													<option value="<%=s%>" selected><%=s%></option>
												<%}
												else{%>
													<option value="<%=s%>" ><%=s%></option>
												<%}
												
										}}%>
									</select> 
								</td>
								<td>
									<select name="selected2">
										<%String[] com = (String[]) request.getAttribute("Commodity");
										if(com!=null){
											
											for(String s:com){
												if(s.equals(details[2])){%>
												<option value="<%=s%>" selected><%=s%></option>
											<%}
											else{%>
												<option value="<%=s%>" ><%=s%></option>
											<%}
											
									}}%>
									</select>
								</td>
								<td> 
									<select name="selected3">
										<%String[] cur = (String[]) request.getAttribute("Currency");
										if(cur!=null){
											for(String s:cur){
												if(s.equals(details[3])){%>
												<option value="<%=s%>" selected><%=s%></option>
											<%}
											else{%>
												<option value="<%=s%>" ><%=s%></option>
											<%}
											
									}}%>
									</select>
								</td>
                           		
                                 <td><input type="date" id="startDate" name="StartDate" placeholder="<%=details[5]%>" value="<%=details[5]%>"></td>
                                 <td><input type="date" id="endDate" name="EndDate" placeholder="<%=details[7]%>" value="<%=details[7]%>"></td>
                                 <td>
                                 <input type="hidden" name="oldFlag" value="<%=details[6]%>">
									<select name="SelectFlag">	
										<% if(details[6].equals("N")){ %>
											<option value="N" selected>No</option>
											<option value="Y">Yes</option>
										<% 	}
											else{%>
												<option value="N">No</option>
												<option value="Y" selected>Yes</option>
											<%}%> 
									</select>
								</td> 
                           </tr>
                           </table>
                          
                           <br>
							<input type="submit" class="button" name="edit" value="Edit">
							 <%} %>
             <br>
             </form>
             <article><%=(request.getAttribute("status") == null) ? "" : request.getAttribute("status")%></article>
       </div>
       <br>
       

</body>
</html>
